package com.mocha.common.core;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @author: songkui
 * @date: 2022/6/21 17:52
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(of = {"total", "size", "current"})
@NoArgsConstructor
public class MochaPage<T> implements Serializable {
    private static final long serialVersionUID = 27684112312312L;

    private List<T> records = Collections.emptyList();

    private Long total;
    private Long size;
    private Long current;

    public MochaPage(List<T> records, Long total, Long size, Long current){
        this.records = records;
        this.total = total;
        this.size = size;
        this.current = current;
    }

    public static <T> MochaPage<T> of(List<T> records){
        return of(records, null, null, null);
    }

    public static <T> MochaPage<T> of(List<T> records, Long total){
        return of(records, total, null, null);
    }

    public static <T> MochaPage<T> of(Long total, Long size, Long current){
        return of(Collections.emptyList(), total, size, current);
    }

    public static <T> MochaPage<T> of(List<T> records, Long total, Long size, Long current){
        return new MochaPage<>(records, total, size, current);
    }


}
